<template>
  <view class="login">
    <view class="tip">uniapp-demo</view>
    <tui-input
      placeholder="请输入账号"
      clearable
      label="账号"
      v-model="accountRef.account"
    ></tui-input>
    <tui-input
      placeholder="请输入密码"
      clearable
      label="密码"
      password
      v-model="accountRef.pwd"
    ></tui-input>
    <view class="login-btn">
      <tui-button @click="loginAction">登录</tui-button>
    </view>
  </view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { login } from '@/api/login'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()
const accountRef = ref({
  account: 'kobe',
  pwd: '123456'
})

async function loginAction() {
  const loginResult = await login({
    name: accountRef.value.account,
    password: accountRef.value.pwd
  })
  userStore.updateUserInfo(loginResult.data)
  uni.switchTab({
    url: '/pages/first/first'
  })
}
</script>
<style lang="scss">
@import './login.scss'
</style>